﻿using CoachingOrganizer.ClientInfrastructure.ServicesEntities.LocalStorage.Tools;
using CoachingOrganizer.ClientInfrastructure.ServicesEntities.LocalStorage.Tools.EmotionsPack;
using CoachingOrganizer.ClientInfrastructure.ServicesEntities.LocalStorage.Tools.MoneyCalculation;
using CoachingOrganizer.ClientInfrastructure.ServicesEntities.LocalStorage.Tools.MoodLevel;
using CoachingOrganizer.Logic.Common;
using CoachingOrganizer.Logic.Logic.Common;
using CoachingOrganizer.Logic.Logic.Tools.EmotionsPack;
using CoachingOrganizer.Logic.Logic.Tools.MoneyCalculation;
using CoachingOrganizer.Logic.Logic.Tools.MoodLevel;
using CoachingOrganizer.Logic.Models.Tools;
using CoachingOrganizer.Logic.Models.Tools.EmotionsPack;
using CoachingOrganizer.Logic.Models.Tools.MoneyCalculation;
using CoachingOrganizer.Logic.Models.Tools.MoodLevel;
using CoachingOrganizer.Toolkit.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoachingOrganizer.Logic.Logic.Tools
{
    internal abstract class ToolLogicBase
    {
        private readonly ToolModelBase _baseModel;
        protected readonly LogicExtender _logicExtender;
        protected readonly GoalLogic _upperLogic;
        private readonly IToolInfo _localBaseData;

        public ToolModelBase BaseModel
        {
            get { return _baseModel; }
        }

        public IToolInfo LocalBaseData
        {
            get { return _localBaseData; }
        }

        public ToolLogicBase(ToolModelBase model, LogicExtender logicExtender, GoalLogic upperLogic, IToolInfo localData)
        {
            _baseModel = model;
            _logicExtender = logicExtender;
            _upperLogic = upperLogic;
            _localBaseData = localData;
        }

        private ActionResult Remove()
        {
            return _upperLogic.RemoveTool(this);
        }

        private ActionResult Save()
        {
            return _localBaseData.Save();
        }

        internal static ToolLogicBase CreateTool(LogicExtender logicExtender, GoalLogic goalLogic, IToolInfo info)
        {
            if (info is IMoodLevelInfo)
                return new MoodLevelLogic(new MoodLevelModel(), logicExtender, goalLogic, (IMoodLevelInfo)info);
            if (info is IMoneyCalculationInfo)
                return new MoneyCalculationLogic(new MoneyCalculationModel(), logicExtender, goalLogic, (IMoneyCalculationInfo)info);
            if (info is IEmotionsPackInfo)
                return new EmotionsPackLogic(new EmotionsPackModel(), logicExtender, goalLogic, (IEmotionsPackInfo)info);
            throw new NotImplementedException();
        }
    }
}
